package com.saibowisdom.storage.aspirator.common;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 说明:
 * 作者: LDL
 * 日期: 2016/6/17.
 */
class C3p0ConnectionPool {


    private static ComboPooledDataSource ds;
    private static C3p0ConnectionPool instance;


    private C3p0ConnectionPool() {
        ds = new ComboPooledDataSource();
    }

    static C3p0ConnectionPool getInstance() {
        if (instance == null) {
            try {
                instance = new C3p0ConnectionPool();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return instance;
    }

    synchronized Connection getConnection() {
        Connection conn = null;
        try {
            conn = ds.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}
